
import { createSlice, configureStore } from "@reduxjs/toolkit"
//  创建切片对象
let conSlice = createSlice({
    name: "count",
    initialState: {
        value: 100,
        age:55
    },
    reducers: {
        jia: function (state, active) {
            state.value += active.payload
        },
        jian(state, active){
            state.value-=active.payload
        }
    }
})


// 2.  // 在切片对象中 提取 action 方法
export let {jia,jian} = conSlice.actions

// 异步加
 export let asynjia = (a)=>{
    return (dispatch)=>{
        setTimeout(() => {
            dispatch(jia(a))
        }, 1000);
    }
}

// 异步减
export let asynjian = (a)=>{
    return (dispatch)=>{
        setTimeout(() => {
            dispatch(jian(a))
        }, 1000);
    }
}
export default conSlice.reducer